package com.zhieasy.service.impl;

import com.zhieasy.common.service.RedisService;
import com.zhieasy.domain.Student;
import com.zhieasy.service.StudentRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author 风亦未止
 * @date 2021/11/20 20:18
 */
@Service
public class StudentRedisServiceImpl implements StudentRedisService {
    @Autowired
    private RedisService redisService;
    @Value("${redis.database}")
    private String REDIS_BASE;
    @Value("${redis.key.token}")
    private String TOKEN;

    @Value("${redis.expire.common}")
    private long expireTime;

    @Override
    public void put(String token, Student student) {
        String key=REDIS_BASE+":"+TOKEN+":"+token;
        redisService.set(key,student,expireTime);
    }

    @Override
    public Object get(String token) {
        String key=REDIS_BASE+":"+TOKEN+":"+token;
        return redisService.get(key);
    }

    @Override
    public boolean remove(String token) {
        String key=REDIS_BASE+":"+TOKEN+":"+token;
       return redisService.del(key);
    }

    @Override
    public void setLimit(String ipUrl, int value, long time) {
        String key=REDIS_BASE+":"+ipUrl;
        redisService.set(key,value,time);
    }

    @Override
    public Object getLimitTime(String ipUrl) {
        String key=REDIS_BASE+":"+ipUrl;
        return redisService.get(key);
    }
}
